package algorithm.linetable.array;

import java.util.HashMap;

public class TwoSum {
    public int[] twosumsolution(int[] nums,Integer target){
        int[] result = new int[2];
        HashMap<Integer,Integer> mymap = new HashMap<Integer, Integer>();
        for(int i=0;i<nums.length;i++){
            mymap.put(nums[i],i);
        }
        for(int i=0;i<nums.length;i++){
            Integer v = mymap.get(target-nums[i]);
            if(v != null && v>i){
                return new int[]{i+1,v+1};
            }
        }
        return result;
    }

    public static void main(String[] args) {
        TwoSum ts = new TwoSum();
        int[] sums = {2,7,10,12};
        int[] a = ts.twosumsolution(sums,9);
        for (int i=0;i<a.length;i++) {
            System.out.println(a[i]);
        }
    }
}
